﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GDIL2
{
    public partial class Catch : Form
    {
        public Catch()
        {
            InitializeComponent();
        }

        Point DownPoint=Point.Empty;
        private bool CatchFinished = false;
        private bool CatchStart = false;
        private Bitmap originBmp;
        private Rectangle CatchRect;

        private void Catch_Load(object sender, EventArgs e)
        {
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer| ControlStyles.AllPaintingInWmPaint| ControlStyles.UserPaint,true);
            this.UpdateStyles();

            originBmp=new Bitmap(this.BackgroundImage);
        }

        private void Catch_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button==MouseButtons.Right)
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }

        private void Catch_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button==MouseButtons.Left)
            {
                if (!CatchStart)
                {
                    CatchStart = true;
                    DownPoint=new Point(e.X,e.Y);
                }
            }
        }

        private void Catch_MouseMove(object sender, MouseEventArgs e)
        {
            if (CatchStart)
            {
                Bitmap destBmp = (Bitmap) originBmp.Clone();
                Point newPoint=new Point(DownPoint.X,DownPoint.Y);
                Graphics g=Graphics.FromImage(destBmp);
                Pen p=new Pen(Color.Blue,1);
                int width = Math.Abs(e.X - DownPoint.X),
                    height = Math.Abs(e.Y - DownPoint.Y);
                if (e.X<DownPoint.X)
                {
                    newPoint.X = e.X;
                }

                if (e.Y<DownPoint.Y)
                {
                    newPoint.Y = e.Y;
                }
            }
        }
    }
}
